package com.wontube.smr.web.client.model.bo;

import java.io.Serializable;

import com.wontube.client.modle.vo.PagenateInfo;

/**
 * query tv , movie params wrapper
 * @author tanggf(2012-8-9)
 *
 */
public class QueryItemParams implements Serializable{
	private static final long serialVersionUID = 1L;
	private String genre;
	/** 年代 */
	private Integer decade;
	/** 首字母 */
	private String initial;
	/** 排序 */
	private String sort;
	/** 更新周期 */
	private String period;
	/** music chart category */
	private String category;	
	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	/** 是否需要返回相关的genres列表 */
	private boolean needGenres;
	
	//=====以下字段不参与查询
	/** 当前请求页码 */
	private Integer page;	
	
	public QueryItemParams() {		
	}
	
	public QueryItemParams(boolean needGenres){
		this.needGenres = needGenres;
	}
	
	public PagenateInfo getPageInfo(int pageSize){
		return new PagenateInfo(getPage(), pageSize);
	}
	public Integer getPage() {
		if(page == null || page.intValue() < 1){
			return 1;
		}
		return page;
	}
	public void setPage(Integer page) {
		this.page = page;
	}		
	public String getGenre() {
		if("".equals(genre) || "all".equals(genre)){
			return null;
		}
		return genre;
	}
	public void setGenre(String genre) {
		this.genre = genre;
	}
	public Integer getDecade() {
		return decade;
	}
	public void setDecade(Integer decade) {
		this.decade = decade;
	}
	public String getInitial() {
		if("".equals(initial)){
			return null;
		}
		return initial;
	}
	public void setInitial(String initial) {
		this.initial = initial;
	}
	public String getSort() {
		if("".equals(sort)){
			return null;
		}
		return sort;
	}
	public void setSort(String sort) {		
		this.sort = sort;
	}
	public boolean isNeedGenres() {
		return needGenres;
	}
	public void setNeedGenres(boolean needGenres) {
		this.needGenres = needGenres;
	}	
	public String getPeriod() {
		if("".equals(period)){
			return null;
		}
		return period;
	}
	public void setPeriod(String period) {
		this.period = period;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1 * prime;
		Integer decade = getDecade();
		if(decade != null){
			result += decade.intValue();
		}		
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		
		QueryItemParams other = (QueryItemParams) obj;
		return this.toString().equals(other.toString());
	}
	
	@Override
	public String toString(){
		StringBuilder sb = new StringBuilder();
		sb.append(getGenre()).append(":")
			.append(getInitial()).append(":")
			.append(getSort()).append(":")
			.append(getDecade()).append(":")
			.append(getPeriod()).append(":")
			.append(getCategory()).append(":")
			.append(isNeedGenres());
		return sb.toString();
	}
}
